package org.clipjoint.service.impl;


import org.clipjoint.dao.CommentAdminDao;
import org.clipjoint.dao.impl.CommentAdminDaoImpl;
import org.clipjoint.entity.dto.CommentDto;
import org.clipjoint.entity.Comment;
import org.clipjoint.service.CommentAdminService;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

public class CommentAdminServiceImpl implements CommentAdminService {
    private CommentAdminDao commentDao=new CommentAdminDaoImpl();
    @Override
    public List<Comment> list(CommentDto commentDto) throws SQLException {
        return  commentDao.selectAll(commentDto);
    }

    @Override
    public Long count(CommentDto commentDto) throws SQLException {
        return commentDao.selectCount(commentDto);
    }

    @Override
    public int deleteAll(List<Long> ids) {
        int result=0;
        //遍历集合
        for (Long id : ids) {

            try {
                result += commentDao.deleteById(id);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }
        return result;
    }

    @Override
    public int del(Long id) throws SQLException {
        return commentDao.deleteById(id);
    }

    @Override
    public Comment getOneById(Long id) throws SQLException {
        return commentDao.selectOne(CommentDto.builder().id(id).build());
    }

    @Override
    public List<Comment> show(Long gameid) throws SQLException {
        return commentDao.show(gameid);
    }

    @Override
    public int add(Comment comment) throws SQLException {
        comment.setCreate_time(new Date());
        return commentDao.add(comment);
    }
}
